<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>07加载网络的geojson数据</title>
    <!-- 1.导入依赖 -->
    <link rel="stylesheet" href="https://lib.baomitu.com/ol3/4.6.5/ol.css" />
    <script src="https://lib.baomitu.com/ol3/4.6.5/ol.js"></script>
  </head>
  <body>
    <!-- 2.设置地图容器的挂载点 -->
    <div id="map"></div>

    <script>
      // 3.初始化一个高德图层(初始化地图)
      const gaode = new ol.layer.Tile({
        title: '高德地图',
        source: new ol.source.XYZ({
          url: 'http://wprd0{1-4}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&style=7&x={x}&y={y}&z={z}',
          wrapX: false,
        }),
      })

      // 4.初始化openlayer地图
      const map = new ol.Map({
        // 将初始化的地图设置到id为map的DOM元素上
        target: 'map',
        layers: [gaode],
        view: new ol.View({
          center: [113.73, 33.62],
          // 设置地图的放大级别
          zoom: 4,
          projection: 'EPSG:4326',
        }),
      })
      // ---------------07加载网络的geojson数据--------------

      // ---------China-------
      const china_source = new ol.source.Vector({
        url: 'https://geo.datav.aliyun.com/areas_v3/bound/100000_full.json',
        format: new ol.format.GeoJSON(),
      })
      const china_layer = new ol.layer.Vector({
        source: china_source,
      })
      const china_style = new ol.style.Style({
        fill: new ol.style.Fill({
          color: 'rgba(50,50,50,0.4)',
        }),
        stroke: new ol.style.Stroke({
          color: 'green',
          width: 2,
        }),
      })
      china_layer.setStyle(china_style)
      map.addLayer(china_layer)

      // ---------HeNan-------
      const henan_source = new ol.source.Vector({
        url: 'https://geo.datav.aliyun.com/areas_v3/bound/410000_full.json',
        format: new ol.format.GeoJSON(),
      })
      const henan_layer = new ol.layer.Vector({
        source: henan_source,
      })
      const henan_style = new ol.style.Style({
        fill: new ol.style.Fill({
          color: 'rgba(90,90,90,0.3)',
        }),
        stroke: new ol.style.Stroke({
          color: 'red',
          width: 2,
        }),
      })
      henan_layer.setStyle(henan_style)
      map.addLayer(henan_layer)
    </script>
  </body>
</html>
